module;
 #include <QObject>
#include <QMap>
#include <QString>
#include <QMutex>
#include <QtCore>
#include <QtCore/QPair>
#include <QThread>
export module ModbusClientThread;
import XYmodbus;

export class ModbusClientThread : public QThread
{
    Q_OBJECT

public:
    explicit ModbusClientThread(QObject *parent = nullptr);
    ~ModbusClientThread();

signals:
    void modbusStateChanged(int state, QString errorMessage);
    void readCompleted(const QString &registerName, const QVariant &registerValue);
    void readCompletedChanged(const QString &registerName, const QVariant &registerValue);
    void allReadCompleted(const QMap<QString, QVariant> &dataMap);
    void writeCompleted(bool success, const QString &registerName, const QString &errorMessage = QString());
    void allWritesCompleted();

    // 新增信号，用于触发 ModbusClientHandle 的槽方法
    void loadConfigSignal(const QString &configFilePath);
    void connectToDeviceSignal();
    void disconnectToDeviceSignal();
    void readModbusValuesSignal();
    void writeModbusValuesSignal(const QMap<QString, QVariant> &wDataMap);

protected:
    void run() override;

private:
    ModbusClientHandle *modbusClientDevice;
};


